﻿Imports System.Collections.ObjectModel
Imports System.Globalization

Public Class ScheduleTask

    Property Handler As DataRowMappedPropertiesHandler = New DataRowMappedPropertiesHandler(Me, "schedule_task", True)
    Property Row As DataRow

    Sub New()
    End Sub

    Sub New(ByVal row As DataRow)
        Me.Row = row
        Me.Handler.RefreshPropertiesFromRow()
    End Sub

    Public Sub New(ByVal id As Integer)
        Me.Handler.ReadDbRecord(id)
    End Sub

    <DbFieldName("id", True)> Property Id As Integer
    <DbFieldName("enddate", False)> Property EndDate As Date
    <DbFieldName("owner", False)> Property Owner As String
    <DbFieldName("period", False)> Property Period As String
    <DbFieldName("amount", False)> Property Amount As Decimal
    <DbFieldName("type", False)> Property RecordType As String
    <DbFieldName("remark", False)> Property Remark As String
    <DbFieldName("modifyby", False)> Property ModifyBy As String
    <DbFieldName("modifydt", False)> Property ModifyAt As DateTime

    Public Shared Function FindAll() As Collection(Of ScheduleTask)
        Dim result As Collection(Of ScheduleTask) = New Collection(Of ScheduleTask)
        Dim sql As String = "select * from schedule_task"
        Dim myTable As DataTable = MysqlDataBaseConnection.RunSelect(sql).Tables(0)
        For Each row As DataRow In myTable.Rows
            result.Add(New ScheduleTask(row))
        Next
        Return result
    End Function

    Public Shared Function FindByOwner(ByVal owner As String) As Collection(Of ScheduleTask)
        Dim result As Collection(Of ScheduleTask) = New Collection(Of ScheduleTask)
        Dim sql As String = "select * from schedule_task where owner = '" + owner + "'"
        Dim myTable As DataTable = MysqlDataBaseConnection.RunSelect(sql).Tables(0)
        For Each row As DataRow In myTable.Rows
            result.Add(New ScheduleTask(row))
        Next
        Return result
    End Function

    Public Sub Create()
        Me.Handler.InsertDbRecord()
    End Sub

    Public Sub Update()
        Me.Handler.UpdateDbRecord()
    End Sub

    Public Sub Delete()
        Me.Handler.DeleteDbRecord()
    End Sub

End Class
